package org.xx.armory.freemarker;

import freemarker.template.DefaultObjectWrapper;
import freemarker.template.SimpleDate;
import freemarker.template.TemplateDateModel;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
import freemarker.template.Version;

import java.util.Date;

public class ExtObjectWrapper
        extends DefaultObjectWrapper {
    public ExtObjectWrapper(
            Version incompatibleImprovements
    ) {
        super(incompatibleImprovements);
    }

    @Override
    public TemplateModel wrap(
            Object obj
    )
            throws TemplateModelException {
        if (obj instanceof Date) {
            return new SimpleDate((Date) obj, TemplateDateModel.DATETIME);
        } else {
            return super.wrap(obj);
        }
    }
}
